package cn.chinaflame.pagodas.schedul;

import cn.chinaflame.pagodas.entity.PaBalmOrder;
import cn.chinaflame.pagodas.utils.ScheduleTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;


/**
 * 调度器
 *
 * @author wwt
 * Created by yw on 2018/10/16.
 */
public class PaBalmOrderSchedule {
    private static ScheduledExecutorService Manager;
    private static PaBalmOrderSchedule paBalmOrderSchedule;

    static {
        Manager = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
    }

    private PaBalmOrderSchedule  () {

    }

    public synchronized static PaBalmOrderSchedule getInstance () {
        if (paBalmOrderSchedule == null) {
            paBalmOrderSchedule = new PaBalmOrderSchedule();
        }
        return paBalmOrderSchedule;
    }

    /**
     * 预约订单时调用，一段时间后订单失效
     */
    public void startTask(Runnable task, ScheduleTime time) {
        Manager.schedule(task, time.getDelay(), time.getTime());
    }



}
